package com.todod.base.module.infra.dal.mysql.file;

import com.todod.base.framework.common.pojo.PageResult;
import com.todod.base.framework.mybatis.core.mapper.BaseMapperX;
import com.todod.base.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.todod.base.module.infra.controller.admin.file.vo.file.FilePageReqVO;
import com.todod.base.module.infra.dal.dataobject.file.FileDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 文件操作 Mapper
 *
 * @author admin
 */
@Mapper
public interface FileMapper extends BaseMapperX<FileDO> {

    default PageResult<FileDO> selectPage(FilePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FileDO>()
                .likeIfPresent(FileDO::getPath, reqVO.getPath())
                .likeIfPresent(FileDO::getType, reqVO.getType())
                .betweenIfPresent(FileDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(FileDO::getId));
    }

    default PageResult<FileDO> findBy(FilePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FileDO>()
                .eq(FileDO::getId, reqVO.getId()));

    }

    default List<FileDO> getListByForeignTableInfo(Long foreignTableId, String foreignTableName, String foreignFileType){
        return selectList(new LambdaQueryWrapperX<FileDO>()
                .eqIfPresent(FileDO::getForeignTableId, foreignTableId)
                .eqIfPresent(FileDO::getForeignTableName, foreignTableName)
                .eqIfPresent(FileDO::getForeignFileType, foreignFileType));
    };

    default List<FileDO> getFileListByUrl(String url){
        return selectList(new LambdaQueryWrapperX<FileDO>().eq(FileDO::getUrl, url));
    };
}
